package com.naxian.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.naxian.mapper.CompanyMapper;
import com.naxian.mapper.RecruitMapper;
import com.naxian.pojo.Company;
import com.naxian.pojo.CompanyExample;
import com.naxian.pojo.Recruit;
import com.naxian.pojo.RecruitExample;
import com.naxian.service.search.SearchCenterService;
import com.naxian.vo.search.SearchCenterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SearchCenterServiceImpl  implements SearchCenterService {

    @Autowired
    private CompanyMapper companyMapper;

    @Autowired
    private RecruitMapper recruitMapper;
//根据关键字（分类）搜索相应的企业和招聘信息
    @Override
    public PageInfo<SearchCenterVo> selectBykey(String keyWord, int pageNum, int pagesize) {
        /*查找全部搜索内容*/
       List<SearchCenterVo> searchCenterVoList= new ArrayList<>();

        RecruitExample recruitExample = new RecruitExample();
        RecruitExample.Criteria recruitCriteria = recruitExample.createCriteria();
        recruitCriteria.andKwdLike(keyWord);

        PageHelper.startPage(pageNum,pagesize);
        List<Recruit> recruitList = this.recruitMapper.selectByExample(recruitExample);
        for (Recruit r:recruitList){
         int   companyId = r.getCompanyId();
            Company  company = companyMapper.selectByPrimaryKey(companyId);
            searchCenterVoList .add(new SearchCenterVo(company,r));
        }
        return new PageInfo<SearchCenterVo>(searchCenterVoList);
    }
//根据招聘名搜索到招聘和公司信息
    @Override
    public PageInfo<SearchCenterVo> selectByRecName(String recName, int pageNum, int pagesize) {
        System.out.println("recName========"+recName);
        //根据简历名查询
        List<SearchCenterVo> searchCenterVoList= new ArrayList<>();
        RecruitExample recruitExample = new RecruitExample();
        RecruitExample.Criteria recruitCriteria = recruitExample.createCriteria();
        String jobName= "%"+recName+"%";
        recruitCriteria.andRecNameLike(jobName);
        PageHelper.startPage(pageNum,pagesize);
        List<Recruit> recruitList = this.recruitMapper.selectByExample(recruitExample);
        for (Recruit r:recruitList){
            int   companyId = r.getCompanyId();
            Company  company = companyMapper.selectByPrimaryKey(companyId);
            searchCenterVoList .add(new SearchCenterVo(company,r));
        }
        return new PageInfo<SearchCenterVo>(searchCenterVoList);
    }



    @Override
    public PageInfo<Recruit> getByExample(int pageNum, int pagetSize, String salary, String education) {
        return null;
    }

    @Override
    public PageInfo<SearchCenterVo> getByInfo(int pageNum, int pagetSize, SearchCenterVo searchCenterVo) {
        return null;
    }


}
